package cn.lovezaoan.hpcenter.parse
{
    import flash.events.Event;
    import flash.events.TimerEvent;
    import flash.utils.Timer;
    import mx.collections.ArrayList;
    import flexunit.framework.TestCase;
    import flexunit.framework.TestSuite;
    import org.flexunit.asserts.fail;
    import org.flexunit.async.Async;
    
    public class HtmlExtractTest
    {
        
        public function HtmlExtractTest()
        {
        }
        
        private var extract2Test:HtmlExtract;
        
        [Test]
        public function extract():void
        {
            //            var asyncHandler:Function = Async.asyncHandler(this, handleTimerComplete, 10000, null, handleTimeout);
            //            timer.addEventListener(TimerEvent.TIMER_COMPLETE, asyncHandler, false, 0, true);
            //			printCurrentDatetime();
            //			timer.start();
        
            //			Async.proceedOnEvent( this, this.extract2Test.html, Event.COMPLETE );
        
            //			this.extract2Test.extract("div");
        }
        
        [Before(async)]
        public function init():void
        {
            var url:String = "http://www.lovezaoan.cn";
            //			url = "http://www.baidu.com";
            
            url = "http://blog.sina.com.cn/zaoanshaonuzuchunchun";
            url = "http://gree.jp/michishige_sayumi/blog";
            url = "http://blog.helloproject.tw/jimmysho";
            url = "http://tieba.baidu.com/f?kw=%D4%E7%B0%B2%C9%D9%C5%AE%D7%E9";
            url = "http://www.helloproject.com.tw";
            url = "http://www.hphello.com/thread78-type127";
            url = "http://blog.sina.com.cn/zaoanshaonuzuchunchun";
            url = "http://blog.helloproject.tw/jimmysho";
            extract2Test = new HtmlExtract(url);
            this.extract2Test.html.addEventListener(Event.COMPLETE, Async.asyncHandler(this, handleHtmlLoaded, 120000, null, handleEventNeverOccurred), false, 0, true);
        }
        
        [After]
        public function tearDown():void
        {
        
        }
        
        protected function handleEventNeverOccurred(passThroughData:Object):void
        {
            fail("Timeout readed before event");
        }
        
        protected function handleHtmlLoaded(event:Event, passThroughData:Object):void
        {
            trace("html load successful!!");
            var rule:String = ".column,.col1,.col1 blog_margin_hack,ul,a";
            rule = "ul";
            
            
            rule = ".content";
            rule = ".title";
            rule = "#thread_list_table,tbody,.thread_title,a"; //贴吧
            rule = "object[width=\"670\"],embed";
            rule = ".content_box_A,.cate_tr_B";
            rule = ".gray2";
            rule = ".content";
            
            var res:ArrayList;
            
            //            var res:ArrayList = extract2Test.extract(rule);
            //            trace("-----html has element:" + res.length);
            //			trace( res.getItemAt(0).outerHTML );
            
            //			res = extract2Test.extract("#nav");
            //			trace("-----html has element:" + res.length);
            //			trace(res.getItemAt(0).outerHTML);
            //			
            var rules:ArrayList = new ArrayList();
            rules.addItem(".blogbox,.ptitle,a");
            rules.addItem(".blogbox,ptext");
            res = extract2Test.extractMultiple(rules);
            trace(res.length);
        
        }
        
        private function printCurrentDatetime():void
        {
            var today:Date = new Date();
            trace(today.toLocaleTimeString());
        }
    }
}